package com.esun.payment_api.bean;

import com.esun.common.constant.Constants;
import com.esun.common.utils.BlankUtils;
import com.esun.common.utils.JWTUtils;
import com.esun.common.utils.SecurityUtils;
import com.esun.payment_api.domain.User;
import lombok.Data;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
public class UserBean {
    private Short id;

    private String uuid;

    private Short coId;

    private String coName;

    private Short deptId;

    private String deptName;

    private String loginName;

    private String userName;

    private String phone;

    private String photo;

    private String email;

    private String status;

    private String roleStr;

    private Date lastLoginTime;

    private String lastLoginIp;

    private Date pwdSetAt;

    private Short pwdErrTimes;

    private Date lockAt;

    private String userType;

    private Short createBy;

    private Date createAt;

    private Short updateBy;

    private Date updateAt;

    private Short deleteBy;

    private Date deleteAt;

    private String remarks;

    private String token;

    //是否需要修改密码:0-否，1-是, 默认1
    private String isUpdatePwd;

    public UserBean() {
    }

    public UserBean(User user, String deptName){
        this.id = user.getId();
        this.uuid = user.getUuid();
        this.coId = user.getCoId();
        this.deptId = user.getDeptId();
        this.loginName = user.getLoginName();
        this.userName = user.getUserName();
        this.phone = user.getPhone();
        this.status = user.getStatus();
        this.roleStr = user.getRoleStr();
        this.lastLoginTime = user.getLastLoginTime();
        this.lastLoginIp = user.getLastLoginIp();
        this.pwdSetAt = user.getPwdSetAt();
        this.pwdErrTimes = user.getPwdErrTimes();
        this.lockAt = user.getLockAt();
        this.userType = user.getUserType();
        this.createBy = user.getCreateBy();
        this.createAt = user.getCreateAt();
        this.updateBy = user.getUpdateBy();
        this.updateAt = user.getUpdateAt();
        this.deleteBy = user.getDeleteBy();
        this.deleteAt = user.getDeleteAt();
        this.remarks = user.getRemarks();
        this.isUpdatePwd = user.getIsUpdatePwd();
        this.deptName = deptName;

        Map map = new HashMap();
        map.put("id", user.getId().toString());
        map.put("uuid", user.getUuid());
        map.put("loginName", user.getLoginName());
        map.put("userName", user.getUserName());
        map.put("roleStr", user.getRoleStr());
        map.put("departmentName",deptName);
        if(BlankUtils.isBlank(user.getCoId())){
            map.put("coId", null);
        }else{
            map.put("coId", user.getCoId().toString());
        }
        if(BlankUtils.isBlank(user.getDeptId())){
            map.put("deptId", null);
        }else{
            map.put("deptId", user.getDeptId().toString());
        }
        this.token = Constants.TOKEN_PREFIX + JWTUtils.createToken(map);

    }
}
